import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex);

export default new Vuex.Store({
  plugins: [
    createPersistedState({
      storage: window.localStorage,
    }),
  ],
  state: {
    //是否显示登录框
    // dialogFormVisible:true,
    //全局用户信息 ，赋值为null
    userInfo: null,
  },
  mutations: {
    //改变登录框显示值
    // changeDialogFormVisible(state) {
    //   state.dialogFormVisible = !state.dialogFormVisible;
    // },

    //全局用户信息
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo;
    },
    //更新本地头像
    SET_AVATAR: (state, avatar) => {
      state.userInfo.avatar = avatar;
    },
    //全局用户权限
    SET_ROLE: (state, role) => {
      state.role = role;
    },
    //清空全局存储的信息
    REMOVE_INFO: (state) => {
      state.userInfo = null;
      state.role = "";
    },
  },

  getters: {
    //get
    getUser: (state) => {
      return state.userInfo;
    },
  },
  actions: {},
  modules: {},
});
